import domain.PType;
import domain.Student;
import domain.Users;
import domain.product;
import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.UserService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**ww
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
//        Student student = (Student)applicationContext.getBean("student");
//        System.out.println(student.getStuname());
//        System.out.println(student.getStucode());
//        System.out.println(student.getGradeClass().getGcname());
//        System.out.println(student.getGradeClass().getGccode());
//        System.out.println(student.getGradeClass().getGrade().getGname());
//        System.out.println(student.getGradeClass().getGrade().getGcode());

//        product product = (product)applicationContext.getBean("product");
//        System.out.println(product.getPid());
//        System.out.println(product.getPname());
//        System.out.println(product.getPcode());
//        System.out.println(product.getPprice());
//        System.out.println(product.getPtid().getPtid());
//        System.out.println(product.getPtid().getPtname());

//        SqlSession sqlSession = MybatisUtil.getSqlSession();
//        UsersMapper usersMapper = sqlSession.getMapper(UsersMapper.class);
//        ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);
//        List<Users> users = usersMapper.findUserAll();
//        List<product> products = productMapper.findProductAll();
//        for (product p:products) {
//            System.out.println(p.getPname() + p.getPcode() + p.getPprice() + p.getPid());
//        }

       //批量添加
        UserService userService = (UserService) applicationContext.getBean("UserService");
        Users u1 = new Users("eeeeeeeeeee","111111");
        Users u2 = new Users("rrrrrrrrrrr","222222");
        Users u3 = new Users("ttttttttttt","333333");

        List<Users> data = new ArrayList<>();
        data.add(u1);
        data.add(u2);
        data.add(u3);
        userService.batchUpdate(data);

//        List<Map<String,Object>> dt = userService.selectUsers("wt");
//        for (Map<String,Object> row:dt) {
//            System.out.println(row);
//        }
    }
}
